import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:flutter_widgets_pc/resources/kq_theme_colors.dart';
import 'package:flutter_widgets_pc/theme/kq_theme_manager.dart';
import 'package:flutter_widgets_pc/widgets/datePicker/kq_date_widget.dart';
import 'package:flutter_widgets_pc/widgets/datePicker/kq_datetime_widget.dart';
import 'package:flutter_widgets_pc/widgets/datePicker/kq_time_widget.dart';

import '../kq_botton_sheet_manger.dart';


/// 通用日期时间选择底部弹窗
///
/// @author 周卓
///
class KqDatePickerBottomSheet extends StatelessWidget {
  /// 能滚动到的最小日期
  final DateTime? minDateTime;

  /// 能滚动到的最大日期
  final DateTime? maxDateTime;

  /// 初始选择的时间。默认当前时间
  final DateTime? initialDateTime;

  /// 时间格式化的格式
  final String? dateFormat;

  /// 分钟间切换的差值
  final int minuteDivider;

  /// 左边按钮文字，默认“取消”
  final String? leftBtnText;

  /// 右边按钮文字，默认“确定”
  final String? rightBtnText;

  /// 时间选择组件显示的时间类型
  final KqDateTimePickerMode pickerMode;

  /// 时间选择组件的主题样式
  final KqPickerTitleConfig pickerTitleConfig;

  /// 点击【取消】回调给调用方的回调事件
  final Function()? onCancel;

  /// 时间滚动选择时候的回调事件
  final Function(DateTime dateTime, List<int> selectedIndex)? onChange;

  final Function(DateTime dateTime, List<int> selectedIndex)? onConfirm;

  const KqDatePickerBottomSheet(
      {Key? key,
      this.minDateTime,
      this.maxDateTime,
      this.initialDateTime,
      this.dateFormat,
      this.leftBtnText,
      this.rightBtnText,
      this.minuteDivider = 1,
      this.onCancel,
      this.onChange,
      this.onConfirm,
      this.pickerMode = KqDateTimePickerMode.date,
      this.pickerTitleConfig = KqPickerTitleConfig.Default})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    Widget? pickerWidget;
    switch (pickerMode) {
      case KqDateTimePickerMode.date:
        pickerWidget = KqDateWidget(
          minDateTime: minDateTime,
          maxDateTime: maxDateTime,
          initialDateTime: initialDateTime,
          dateFormat: dateFormat,
          leftBtnText: leftBtnText,
          rightBtnText: rightBtnText,
          pickerTitleConfig: pickerTitleConfig,
          onCancel: onCancel,
          onChange: onChange,
          onConfirm: onConfirm,
          showBottomButton: false,
        );
        break;
      case KqDateTimePickerMode.time:
        pickerWidget = KqTimeWidget(
          minDateTime: minDateTime,
          maxDateTime: maxDateTime,
          initDateTime: initialDateTime,
          dateFormat: dateFormat,
          leftBtnText: leftBtnText,
          rightBtnText: rightBtnText,
          minuteDivider: minuteDivider,
          pickerTitleConfig: pickerTitleConfig,
          onCancel: onCancel,
          onChange: onChange,
          onConfirm: onConfirm,
          showBottomButton: false,
        );
        break;
      case KqDateTimePickerMode.datetime:
        pickerWidget = KqDateTimeWidget(
          minDateTime: minDateTime,
          maxDateTime: maxDateTime,
          initDateTime: initialDateTime,
          dateFormat: dateFormat,
          leftBtnText: leftBtnText,
          rightBtnText: rightBtnText,
          minuteDivider: minuteDivider,
          pickerTitleConfig: pickerTitleConfig,
          onCancel: onCancel,
          onChange: onChange,
          onConfirm: onConfirm,
          showBottomButton: false,
        );
        break;
    }

    return UnconstrainedBox(
        child: SizedBox(
            width: context.width,
            child: Material(
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(KqThemeManager.instance
                                .getConfig()
                                .dialogConfig
                                .radius ??
                            8),
                        topRight: Radius.circular(KqThemeManager.instance
                                .getConfig()
                                .dialogConfig
                                .radius ??
                            8))),
                color:
                    KqThemeManager.instance.getConfig().dialogConfig.bgColor ??
                        KqThemeColors.bgWhite,
                child: ClipRRect(
                  borderRadius: BorderRadius.only(
                      topLeft: Radius.circular(KqThemeManager.instance
                              .getConfig()
                              .dialogConfig
                              .radius ??
                          8),
                      topRight: Radius.circular(KqThemeManager.instance
                              .getConfig()
                              .dialogConfig
                              .radius ??
                          8)),
                  child: pickerWidget,
                ))));
  }
}


///时间选择模式枚举
enum KqDateTimePickerMode {
  /// Display DatePicker
  date,

  /// Display TimePicker
  time,

  /// Display DateTimePicker
  datetime,
}